package com.zmn.mcc.cas.server.boot.autoconfigure;

import com.zmn.base.common.data.dubbo.interfaces.company.CompanyListRemoteService;
import com.zmn.mcc.cache.StaffCache;
import com.zmn.mcc.cas.server.WhitelistService;
import com.zmn.mcc.cas.server.WhitelistServiceImpl;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.RedisTemplate;

/**
 * @author quanjic
 * @version v1.0
 * @since 2020/6/17 10:40
 **/
@Configuration
@EnableConfigurationProperties(WhitelistProperties.class)
public class WhitelistConfiguration {

    @Bean
    public WhitelistService whitelistService(WhitelistProperties properties, CompanyListRemoteService companyService, RedisTemplate redisTemplate, StaffCache staffCache) {
        WhitelistServiceImpl whitelistService = new WhitelistServiceImpl(properties.getIpWhitelistUrl(), properties.getExpiredSecond(), properties.getNoCheckAreaId());
        whitelistService.setCompanyService(companyService);
        whitelistService.setRedisTemplate(redisTemplate);
        whitelistService.setStaffCache(staffCache);
        whitelistService.setIntranetSegmentList(properties.getIntranetSegmentList());
        return whitelistService;
    }

}
